package demo7;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Person {
    private String name;
    public Person(){
        System.out.println("构造器执行");
    }

    public String getName() {
        System.out.println("Person的setName");
        return name;
    }
@Value("张三")
    public void setName(String name) {
    System.out.println("this setname");
        this.name = name;
    }
    @PostConstruct
    //Spring容器实例化该对象并初始化其中的属性都完毕后，会调用这个方法通知该对象初始化完毕
    public void init(){
        System.out.println("Person init");
    }
    @PreDestroy
    //容器销毁前调用
    public void destroy(){
        System.out.println("Person destroy()");
    }

    /**
     * 垃圾回收机制调用
     *
     */
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }
}

